package org.jsola.hr.web;

import org.jsola.contract.query.ContractQuery;
import org.jsola.contract.vo.ContractCountVO;
import org.jsola.core.Result;
import org.jsola.hr.constant.HrConstants;
import org.jsola.hr.provider.IContractProviderService;
import org.jsola.user.core.TokenUser;
import org.jsola.user.core.UserContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 合同总览
 *
 * @author huangrun
 */
@RestController("hrContractOverviewController")
@RequestMapping(HrConstants.API_PATH + "/v1/overview")
public class ContractOverviewController implements IContractOverviewControllerAPI {

    private static final Logger log = LoggerFactory.getLogger(ContractOverviewController.class);

    /**
     * 合同类型 电子合同
     */
    private static final Integer CONTRACT_TYPE = 1;

    /**
     * 公司id 默认 null
     */
    private static final String SUBJECT_ID = null;

    @Autowired
    private IContractProviderService contractProviderService;


    @Override
    @GetMapping(value = "/getContractCount")
    public Result<ContractCountVO> getContractCount() {
        TokenUser tokenUser = UserContext.getUser();
        // todo 查看备忘录权限校验

        return Result.success(
                contractProviderService.getContractCount(CONTRACT_TYPE, SUBJECT_ID, tokenUser)
        );
    }

    @Override
    @PostMapping(value = "/getContractCountBySubjectIds")
    public Result<ContractCountVO> getContractCountBySubjectIds(@RequestBody ContractQuery contractQuery) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 查看备忘录权限校验

        return Result.success(
                contractProviderService.getContractCount(CONTRACT_TYPE, contractQuery.getSubjectIds(), tokenUser)
        );
    }

}
